import moment from 'moment';  	// 这个moment方法。框架里本来就有引入就好
import { Program } from '@/data-type.d';
import { request } from 'umi';
//格式化时间显示
export const FormatterTime = (val: Date) => {
  return val ? moment(val).format('YYYY-MM-DD') : ''
}

//获取Obj中对应K的值
function getProp<T, K extends keyof T>(obj: T, key: K) {
  return obj[key] ?? '';
}
//demo
function forPromgram(program: Program) {
  request("http://localhost:8080/api", {
    method: "GET",
    data: JSON.stringify(program)
  }).then(response => {
    let p: Program = response.data.data
    // return response;
  })
}
export function needbackButton(state: any): boolean {
  if (typeof (state?.id) == 'number') {
    return true;
  }
  return false;
}
export function getIdFromHistory(state: any): number | null {
  if (needbackButton(state)) {
    return state.id;
  }
  return null;
}